﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace com.lib.data
{
    public class IData : DataManager
    {
        /// <summary>
        /// 定义类
        /// </summary>
        private static Dictionary<string, object> data = new Dictionary<string, object>();

        private static IData instance = null;

        /// <summary>
        /// 实例类参考
        /// </summary>
        public static IData Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new IData();
                }
                return instance;
            }
        }


        public  bool Set(string key, object val)
        {
            if (Exit(key))
            {
                data[key] = val;
                return false;
            }
            data.Add(key, val);
            return true;
        }

        /// <summary>
        /// 是否凑在
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public  bool Exit(string key)
        {
            return data.ContainsKey(key);
        }

        /// <summary>
        /// 移除
        /// </summary>
        /// <param name="key"></param>
        public void Remove(string key)
        {
            if (Exit(key))
            {
                data.Remove(key);
            }
            
        }

        /// <summary>
        /// 数据长度
        /// </summary>
        public int getCount
        {
            get
            {
                return data.Count;
            }
        }

        /// <summary>
        /// 取得数据
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public object Get(string key)
        {
            if (Exit(key))
            {
                return data[key];
            }
            return null;
        }
    }
}
